import 'package:flutter/material.dart';
import 'package:ycbl/config/bl_color.dart';
import 'package:ycbl/config/bl_style.dart';
import 'package:ycbl/model/calendar_task_list_entity.dart';
import 'package:ycbl/plugin/gensee_live_plugin.dart';
import 'package:ycbl/utils/live_helper.dart';
import 'package:ycbl/utils/toast_util.dart';
import 'package:ycbl/utils/user_config.dart';
import 'package:ycbl/widget/image.dart';
import 'package:ycbl/ext/common_ext.dart';

///日历任务 item （ListView 的 item 都应该是 StatelessWidget 的）
class BLCalendarTaskItem extends StatelessWidget {

  final CalendarTaskEntity calendarTask;

  const BLCalendarTaskItem({Key key, @required this.calendarTask}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        color: BLColor.whiteColor,
        padding: EdgeInsets.all(12),
        child: SizedBox(
          height: 42,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              //开始时间、结束时间
              Column(
                //mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  //时间的字体比较小，如果想和标题对齐，需要上边加点边距
                  Padding(
                    padding: EdgeInsets.only(top: 2),
                    child: Text(calendarTask?.beginTime ?? '', style: BLStyle.smallTextStyle.wrapHeight(),),
                  ),
                  //SizedBox(height: 10,),
                  Text(calendarTask?.endTime ?? '', style: BLStyle.smallTextStyle.wrapHeight(),),
                ],
              ),
              //分割线
              VerticalDivider(thickness: 1, ),
              // 主标题 、 副标题
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    //SizedBox(height: 8,),
                    Text(calendarTask?.shopName ?? '', style: BLStyle.commonBlackTextStyle.wrapHeight(), maxLines: 1, overflow: TextOverflow.ellipsis,),
                    //SizedBox(height: 10,),
                    Text(calendarTask?.courseName ?? '', style: BLStyle.smallTextStyle.wrapHeight(),),
                  ],
                ),
              ),
              //图标
              LocalImage('ic_task_live.png', width: 22, height: 22,),
            ],
          ),
        ),

      ),

      onTap: () {
        if (calendarTask == null) return;
        //进入展示互动直播 or 回放
        LiveHelper.startGensee(calendarTask.liveUrl, calendarTask.liveToken, calendarTask.vodUrl,
            calendarTask.vodToken, calendarTask.courseStartTime, calendarTask.courseEndTime);
      },
    );
  }
}
